#ifndef _game_h_included_
#define _game_h_included_

#include "Header.h"
#include <d3dx9.h>
#include <d3d9.h>
#include <fstream>
#include <iostream>  
#include "DXUtil.h"
#include "Camera.h"
#include "Model.h"
#include "Light.h"
#include "Mesh.h"
#include <vector>
#include "KeyFrame.h"
#include "PhysicsWorld.h"
#include "Node.h"
#include "BVHMotion.h"
#include "Fractaltree.h"
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h> // DirectX/Direct Input

using namespace std;

class BVHMotion;
class FractalTree;

//The basis for the scene.
//Controls updates, drawing and removal or models.
class Game
{
	//Models
	vector<Model*> mModels;
	
	//Lights: Support enabled for multiple light sources.  
	vector<Light*> mLights;
	
	//Camera:  only one camera is supported 
	//			but more could be added;
	Camera* mCamera;

	//Calculates the total time
	double mTotalTime;

	//The identity Matrix
	D3DXMATRIX mIdentity;
	
	PhysicsWorld* mPhysWorld;

	BVHMotion* bvh;
	FractalTree* tree;


public:

	string input;
	//Creates the scene
	void Initialize(LPDIRECT3DDEVICE9 myDevice, LPDIRECT3D9 myDirect3D);

	//All scene specific ini's go here
	void IniScene(LPDIRECT3DDEVICE9 myDevice);
		
	void LoadContent(LPDIRECT3DDEVICE9 myDevice);
	//Updates the scene
	void Update(LPDIRECT3DDEVICE9 d3ddev, double pElapsedTime); 
	//Draws the scene
	void Draw(LPDIRECT3DDEVICE9 d3ddev);

	//Releases all data for the scene.
	void Release();

	D3DVECTOR* DetermineEllipseTangent(D3DVECTOR* circle,D3DVECTOR* point );

	void Tokenize(const string& str,
                      vector<string>& tokens,
                      const string& delimiters = " ")
	{
		// Skip delimiters at beginning.
		string::size_type lastPos = str.find_first_not_of(delimiters, 0);
		// Find first "non-delimiter".
		string::size_type pos     = str.find_first_of(delimiters, lastPos);

		while (string::npos != pos || string::npos != lastPos)
		{
			// Found a token, add it to the vector.
			tokens.push_back(str.substr(lastPos, pos - lastPos));
			// Skip delimiters.  Note the "not_of"
			lastPos = str.find_first_not_of(delimiters, pos);
			// Find next "non-delimiter"
			pos = str.find_first_of(delimiters, lastPos);
		}
	}
};
#endif
